﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LotteryVote.Logic;
using LotteryVote.Entity;
using LotteryVote.Logic.Web;
using LotteryVote.Utility;

namespace LotteryVote
{
    public partial class AddTodayLotteryResult : CompanyPage
    {
        public IList<CompanyTypeSupportNumLen> NumLenSupportList { get; private set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            Execute(() =>
            {
                if (!IsPostBack)
                    BindTodayCompanys();
            });
        }

        void BindTodayCompanys()
        {
            rbl_company.DataSource = TodayLotteryCompany.Instance.GetTodayCompany();
            rbl_company.DataTextField = LotteryCompany.NAME;
            rbl_company.DataValueField = LotteryCompany.COMPANYID;
            rbl_company.DataBind();
        }
        void BindCompanyRecords()
        {
            NumLenFacade numLenFacade = new NumLenFacade();
            NumLenSupportList = numLenFacade.GetNumLengthByCompanyId(int.Parse(rbl_company.SelectedValue));
        }

        protected void rbl_company_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindCompanyRecords();
        }

        protected void btn_submit_Click(object sender, EventArgs e)
        {
            Execute(() =>
            {
                var numRecords = JSONHelper.ToObject<List<LotteryRecord>>(hd_companyValue.Value);
                LotteryResultFacade lrFacade = new LotteryResultFacade();
                lrFacade.AddLotteryResult(int.Parse(rbl_company.SelectedValue), numRecords);
                ShowMessage("Success", GetGlobalResourceObject("Resource", "Success").ToString());
            });
        }
    }
}